
from fuzzy.utils import MembershipFunctionAlreadyExsists
from membership_functions import TriFuzzyMember,TrapFuzzyMember
from fuzzy.modifier import NOT,VERY


class LinguisticVariable(object):
    
    def __init__(self,name):
        self.name = name
        self.members = {}
        
        
    def add_member(self,aFuzzyMembershipFunction):
        if aFuzzyMembershipFunction.name in self.members.keys():
            raise MembershipFunctionAlreadyExsists(aFuzzyMembershipFunction)
        
        self.members[ aFuzzyMembershipFunction.name ] = aFuzzyMembershipFunction
        
    def __call__(self,aCrisp):
        degrees = {}
        
        for key in self.members.keys():
            degrees[key] = self.members[key](aCrisp)
            
        return degrees
    
    
            
            
a = LinguisticVariable("age")
a.add_member(TrapFuzzyMember("young", 0, 0, 25, 50))
a.add_member(TriFuzzyMember("middle", 25, 50, 750))
a.add_member(TrapFuzzyMember("old", 50, 75, 100, 100))

print a(30),NOT(a(30)),VERY(a(30))
